@isTest
private class RightsConfirmationControllerTest {
    static testMethod void testMethod1() {
        
          //客户1
        Account acc = TestUtils.createAccount();
        acc.Level__c = '三级甲等';
        acc.NCICCode__c = 'testAccount';

        insert acc;

         Id ldcProfile = [Select Id From Profile Where Name like '%工程师%' limit  1  ].Id;

         User u1 = new User( Alias = 'samLdc1', 
                         Email = 'ldc@test.com.maike',
                         Emailencodingkey = 'UTF-8', 
                         Lastname = '用户1', 
                         Languagelocalekey = 'en_US',
                         Localesidkey = 'en_US', 
                         Profileid = ldcProfile, 
                         Country = 'United States',
                         IsActive = true,
                         CompanyName= 'Y-MKSY',
                         SubCompany__c='四川省迈克实业有限公司',
                         UserDepartment__c='客户服务中心(工程部)',
                         Timezonesidkey = 'America/Los_Angeles', 
                         EmployeeNumber = '123451',
                         Province__c = '四川省',
                         ManagerId=UserInfo.getUserId(),
                         Username = 'Matldc1@test.com.maike',
                         FederationIdentifier ='123451', 
                         ResponseCode__c = 'TTTT' );
         insert u1;


         PerformanceRightsConfirmation__c prc = new PerformanceRightsConfirmation__c();
         prc.Year__c ='2020年';
         prc.Quarter__c= '1';
         prc.Account__c = acc.Id;
         prc.Province__c = '四川';

         prc.Company__c = 'MKSY';
         prc.POCTOwner__c = u1.Id;

         insert prc;

    	//调整权限申请
        RightsConfirmation__c rc = new RightsConfirmation__c();

        rc.Province__c= '四川';
        rc.Company__c = 'MKSY';
        rc.Year__c = '2020年';
        rc.Quarter__c = '2';
        rc.Only__c = rc.Year__c +'-'+rc.Quarter__c+'-'+rc.Province__c+'-'+rc.Company__c;

        insert rc;

        //调整权限的 明细

        RightsConfirmationList__c rc1 = new RightsConfirmationList__c();
        rc1.AccountPK__c = 'testAccount';
        rc1.TerminalPK__c = 'testTerminal';
        rc1.Province__c = '四川';
        rc1.Year__c = '2020年';
        rc1.Quarter__c='2';

        rc1.Company__c = 'MKSY';

        insert rc1;


        RightsConfirmationController.DetailBean rcbean = new RightsConfirmationController.DetailBean(rc1);


        RightsConfirmationController rctr = new RightsConfirmationController();
        PageReference page2 = new PageReference('/apex/RightsConfirmation?id='+rc.Id);
        System.Test.setCurrentPage(page2);
        rctr.init();

        User u = [select Id,ExuserCode__c from User where Id=:UserInfo.getUserId()];
        List<String> uss = new List<String>{u.ExuserCode__c};
        RightsConfirmationController.matchUser(uss);

        List<Object> saveList = new List<Object>{rcbean};




        rctr.saveJson = EncodingUtil.urlEncode(JSON.serialize(saveList), 'UTF-8');
        RightsConfirmationController.importData(rctr.saveJson, uss, '2020年', '2');

        rctr.save();

        PerformanceRightsConfirmationHandler.summitApporval(rc.Id);

        rc.Status__c = '审批成功';
        update rc;

    }
}